

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN"
  "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">


<html xmlns="http://www.w3.org/1999/xhtml">
  <head>
    <meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
    
    <title>agpy.get_cutouts &mdash; agpy 0.1.2 documentation</title>
    
    <link rel="stylesheet" href="../../_static/extra.css" type="text/css" />
    <link rel="stylesheet" href="../../_static/pygments.css" type="text/css" />
    
    <script type="text/javascript">
      var DOCUMENTATION_OPTIONS = {
        URL_ROOT:    '../../',
        VERSION:     '0.1.2',
        COLLAPSE_INDEX: false,
        FILE_SUFFIX: '.html',
        HAS_SOURCE:  true
      };
    </script>
    <script type="text/javascript" src="../../_static/jquery.js"></script>
    <script type="text/javascript" src="../../_static/underscore.js"></script>
    <script type="text/javascript" src="../../_static/doctools.js"></script>
    <link rel="top" title="agpy 0.1.2 documentation" href="../../index.html" />
    <link rel="up" title="agpy" href="../agpy.html" />
     
    <script type="text/javascript">

      var _gaq = _gaq || [];
      _gaq.push(['_setDomainName', 'pyspeckit.bitbucket.org']);
      _gaq.push(['_setAllowHash', false]);
      _gaq.push(['_trackPageview']);


    </script>
    <link rel="stylesheet" type="text/css" href="../../_static/extra.css" />
  </head>
  <body>
    <div class="header-wrapper">
      <div class="header">
        <h1><a href="../../index.html">agpy 0.1.2 documentation</a></h1>
        <div class="rel">
          <a href="http://agpy.googlecode.com">agpy Home </a>  |
          <a href=../../index.html>Docs Home </a>  |
          <a href="http://code.google.com/p/agpy/w/list">Wiki</a>  |
          <a href=../../search.html>Search </a>
        </div>
       </div>
    </div>

    <div class="content-wrapper">
      <div class="content">
        <div class="document">
            
      <div class="documentwrapper">
        <div class="bodywrapper">
          <div class="body">
            
  <h1>Source code for agpy.get_cutouts</h1><div class="highlight"><pre>
<span class="sd">&quot;&quot;&quot;</span>
<span class="sd">Make cutouts with all available data of a given position</span>
<span class="sd">&quot;&quot;&quot;</span>
<span class="kn">import</span> <span class="nn">glob</span>
<span class="kn">import</span> <span class="nn">pyfits</span>
<span class="kn">import</span> <span class="nn">pywcs</span>
<span class="kn">import</span> <span class="nn">coords</span>
<span class="kn">import</span> <span class="nn">os</span>
<span class="kn">import</span> <span class="nn">agpy.cubes</span><span class="o">,</span><span class="nn">agpy.grep</span><span class="o">,</span><span class="nn">agpy.cutout</span>
<span class="kn">import</span> <span class="nn">timer</span>

<span class="nd">@timer.print_timing</span>
<span class="k">def</span> <span class="nf">findimages</span><span class="p">(</span><span class="n">xc</span><span class="p">,</span> <span class="n">yc</span><span class="p">,</span> <span class="n">searchpath</span><span class="p">,</span> <span class="n">coordsys</span><span class="o">=</span><span class="s">&#39;celestial&#39;</span><span class="p">,</span> <span class="n">verbose</span><span class="o">=</span><span class="bp">False</span><span class="p">,</span>
        <span class="n">ignore_imagetypes</span><span class="o">=</span><span class="p">(</span><span class="s">&#39;_area&#39;</span><span class="p">,</span><span class="s">&#39;power&#39;</span><span class="p">,</span><span class="s">&#39;angle&#39;</span><span class="p">,</span><span class="s">&#39;weight&#39;</span><span class="p">,</span><span class="s">&#39;residual&#39;</span><span class="p">,</span><span class="s">&#39;smooth&#39;</span><span class="p">,</span><span class="s">&#39;model&#39;</span><span class="p">,</span><span class="s">&#39;mask&#39;</span><span class="p">,</span><span class="s">&#39;noise&#39;</span><span class="p">,</span><span class="s">&#39;label&#39;</span><span class="p">,</span><span class="s">&#39;nhits&#39;</span><span class="p">,</span><span class="s">&#39;covg&#39;</span><span class="p">,</span><span class="s">&#39;std&#39;</span><span class="p">,</span><span class="s">&#39;rms&#39;</span><span class="p">)):</span>
    <span class="sd">&quot;&quot;&quot;</span>
<span class="sd">    Given a single coordinate pair, searches for images that contain the coordinate</span>
<span class="sd">    &quot;&quot;&quot;</span>
    <span class="k">if</span> <span class="n">verbose</span><span class="p">:</span> <span class="k">print</span> <span class="s">&quot;Searching </span><span class="si">%s</span><span class="s">&quot;</span> <span class="o">%</span> <span class="n">searchpath</span>
    <span class="n">imlist</span> <span class="o">=</span> <span class="n">glob</span><span class="o">.</span><span class="n">glob</span><span class="p">(</span><span class="n">searchpath</span><span class="o">+</span><span class="s">&quot;/*.fits&quot;</span><span class="p">)</span>
    <span class="k">for</span> <span class="n">ign</span> <span class="ow">in</span> <span class="n">ignore_imagetypes</span><span class="p">:</span> <span class="c"># remove undesired image types</span>
        <span class="n">imlist</span> <span class="o">=</span> <span class="n">agpy</span><span class="o">.</span><span class="n">grep</span><span class="o">.</span><span class="n">grepv</span><span class="p">(</span><span class="n">ign</span><span class="p">,</span> <span class="n">imlist</span><span class="p">)</span>
    <span class="n">matchlist</span> <span class="o">=</span> <span class="p">[]</span>
    <span class="k">for</span> <span class="n">fn</span> <span class="ow">in</span> <span class="n">imlist</span><span class="p">:</span>
        <span class="k">try</span><span class="p">:</span> 
            <span class="n">head</span> <span class="o">=</span> <span class="n">pyfits</span><span class="o">.</span><span class="n">getheader</span><span class="p">(</span><span class="n">fn</span><span class="p">)</span>
        <span class="k">except</span><span class="p">:</span> <span class="c"># generic exception; there are lots of ways file reading could fail but I don&#39;t care</span>
            <span class="k">continue</span>
        <span class="n">head</span> <span class="o">=</span> <span class="n">agpy</span><span class="o">.</span><span class="n">cubes</span><span class="o">.</span><span class="n">flatten_header</span><span class="p">(</span> <span class="n">head</span> <span class="p">)</span>
        <span class="k">if</span> <span class="n">coords_in_image</span><span class="p">(</span><span class="n">xc</span><span class="p">,</span><span class="n">yc</span><span class="p">,</span><span class="n">head</span><span class="p">,</span><span class="n">coordsys</span><span class="o">=</span><span class="n">coordsys</span><span class="p">):</span>
            <span class="n">matchlist</span><span class="o">.</span><span class="n">append</span><span class="p">(</span><span class="n">fn</span><span class="p">)</span>
            <span class="k">if</span> <span class="n">verbose</span><span class="p">:</span>
                <span class="k">print</span> <span class="s">&quot;Matched </span><span class="si">%s</span><span class="s">&quot;</span> <span class="o">%</span> <span class="n">fn</span>

    <span class="k">if</span> <span class="nb">len</span><span class="p">(</span><span class="n">matchlist</span><span class="p">)</span> <span class="o">&gt;</span> <span class="mi">1</span> <span class="ow">and</span> <span class="nb">type</span><span class="p">(</span><span class="n">matchlist</span><span class="p">[</span><span class="mi">0</span><span class="p">])</span> <span class="ow">is</span> <span class="nb">list</span><span class="p">:</span>
        <span class="c"># remove blanks / make into a single list</span>
        <span class="k">return</span> <span class="nb">reduce</span><span class="p">(</span><span class="k">lambda</span> <span class="n">a</span><span class="p">,</span><span class="n">b</span><span class="p">:</span> <span class="n">a</span><span class="o">+</span><span class="n">b</span><span class="p">,</span><span class="n">matchlist</span><span class="p">,[])</span>
    <span class="k">else</span><span class="p">:</span>
        <span class="k">return</span> <span class="n">matchlist</span>

<span class="c">#@timer.print_timing # this gets called too many times</span>
<div class="viewcode-block" id="coords_in_image"><a class="viewcode-back" href="../../agpy.html#agpy.get_cutouts.coords_in_image">[docs]</a><span class="k">def</span> <span class="nf">coords_in_image</span><span class="p">(</span><span class="n">xc</span><span class="p">,</span><span class="n">yc</span><span class="p">,</span><span class="n">header</span><span class="p">,</span><span class="n">coordsys</span><span class="o">=</span><span class="s">&#39;celestial&#39;</span><span class="p">):</span>
    <span class="sd">&quot;&quot;&quot;</span>
<span class="sd">    Determine whether the coordinates are within the boundaries of the image</span>
<span class="sd">    &quot;&quot;&quot;</span>
    <span class="k">try</span><span class="p">:</span>
        <span class="n">wcs</span> <span class="o">=</span> <span class="n">pywcs</span><span class="o">.</span><span class="n">WCS</span><span class="p">(</span><span class="n">header</span><span class="p">)</span>
    <span class="k">except</span><span class="p">:</span> <span class="c"># if the header isn&#39;t WCS compatible, we don&#39;t want it</span>
        <span class="k">return</span> <span class="bp">False</span>

    <span class="k">try</span><span class="p">:</span>
        <span class="k">if</span> <span class="n">coordsys</span><span class="o">==</span><span class="s">&#39;celestial&#39;</span> <span class="ow">and</span> <span class="n">wcs</span><span class="o">.</span><span class="n">wcs</span><span class="o">.</span><span class="n">lngtyp</span><span class="o">==</span><span class="s">&#39;GLON&#39;</span><span class="p">:</span>
            <span class="n">xc</span><span class="p">,</span><span class="n">yc</span> <span class="o">=</span> <span class="n">coords</span><span class="o">.</span><span class="n">Position</span><span class="p">((</span><span class="n">xc</span><span class="p">,</span><span class="n">yc</span><span class="p">),</span><span class="n">system</span><span class="o">=</span><span class="n">coordsys</span><span class="p">)</span><span class="o">.</span><span class="n">galactic</span><span class="p">()</span>
        <span class="k">elif</span> <span class="n">coordsys</span><span class="o">==</span><span class="s">&#39;galactic&#39;</span> <span class="ow">and</span> <span class="n">wcs</span><span class="o">.</span><span class="n">wcs</span><span class="o">.</span><span class="n">lngtyp</span><span class="o">==</span><span class="s">&#39;RA&#39;</span><span class="p">:</span>
            <span class="n">xc</span><span class="p">,</span><span class="n">yc</span> <span class="o">=</span> <span class="n">coords</span><span class="o">.</span><span class="n">Position</span><span class="p">((</span><span class="n">xc</span><span class="p">,</span><span class="n">yc</span><span class="p">),</span><span class="n">system</span><span class="o">=</span><span class="n">coordsys</span><span class="p">)</span><span class="o">.</span><span class="n">j2000</span><span class="p">()</span>

        <span class="n">xp</span><span class="p">,</span><span class="n">yp</span> <span class="o">=</span> <span class="n">wcs</span><span class="o">.</span><span class="n">wcs_sky2pix</span><span class="p">(</span><span class="n">xc</span><span class="p">,</span><span class="n">yc</span><span class="p">,</span><span class="mi">0</span><span class="p">)</span>
    <span class="k">except</span><span class="p">:</span>
        <span class="k">return</span> <span class="bp">False</span>

    <span class="k">if</span> <span class="n">xp</span> <span class="o">&gt;</span> <span class="n">wcs</span><span class="o">.</span><span class="n">naxis1</span> <span class="ow">or</span> <span class="n">xp</span> <span class="o">&lt;</span> <span class="mi">0</span><span class="p">:</span>
        <span class="k">return</span> <span class="bp">False</span>
    <span class="k">elif</span> <span class="n">yp</span> <span class="o">&gt;</span> <span class="n">wcs</span><span class="o">.</span><span class="n">naxis2</span> <span class="ow">or</span> <span class="n">yp</span> <span class="o">&lt;</span> <span class="mi">0</span><span class="p">:</span>
        <span class="k">return</span> <span class="bp">False</span>
    <span class="k">else</span><span class="p">:</span>
        <span class="k">return</span> <span class="bp">True</span>
</div>
<span class="nd">@timer.print_timing</span>
<span class="k">def</span> <span class="nf">find_all_images</span><span class="p">(</span><span class="n">xc</span><span class="p">,</span><span class="n">yc</span><span class="p">,</span><span class="n">dirlist</span><span class="p">,</span> <span class="n">flatten</span><span class="o">=</span><span class="bp">False</span><span class="p">,</span> <span class="o">**</span><span class="n">kwargs</span><span class="p">):</span>
    <span class="sd">&quot;&quot;&quot;</span>
<span class="sd">    Given a list of directories, search all the directories for overlap with the coordinate</span>
<span class="sd">    &quot;&quot;&quot;</span>
    <span class="n">imlist</span> <span class="o">=</span> <span class="p">[</span><span class="n">findimages</span><span class="p">(</span><span class="n">xc</span><span class="p">,</span><span class="n">yc</span><span class="p">,</span><span class="n">dire</span><span class="p">,</span><span class="o">**</span><span class="n">kwargs</span><span class="p">)</span> <span class="k">for</span> <span class="n">dire</span> <span class="ow">in</span> <span class="n">dirlist</span> <span class="k">if</span> <span class="n">dire</span> <span class="ow">is</span> <span class="ow">not</span> <span class="p">[]]</span>
    <span class="k">if</span> <span class="n">flatten</span> <span class="ow">and</span> <span class="nb">type</span><span class="p">(</span><span class="n">imlist</span><span class="p">[</span><span class="mi">0</span><span class="p">])</span> <span class="ow">is</span> <span class="nb">list</span><span class="p">:</span>
        <span class="k">return</span> <span class="nb">reduce</span><span class="p">(</span><span class="k">lambda</span> <span class="n">a</span><span class="p">,</span><span class="n">b</span><span class="p">:</span> <span class="n">a</span><span class="o">+</span><span class="n">b</span><span class="p">,</span> <span class="n">imlist</span><span class="p">,</span> <span class="p">[])</span>
    <span class="k">else</span><span class="p">:</span>
        <span class="k">return</span> <span class="n">imlist</span>

<span class="nd">@timer.print_timing</span>
<span class="k">def</span> <span class="nf">get_cutouts</span><span class="p">(</span><span class="n">xcoord</span><span class="p">,</span><span class="n">ycoord</span><span class="p">,</span><span class="n">xwidth</span><span class="p">,</span><span class="n">ywidth</span><span class="p">,</span> <span class="n">coordsys</span><span class="o">=</span><span class="s">&#39;galactic&#39;</span><span class="p">,</span>
        <span class="n">ignore_imagetypes</span><span class="o">=</span><span class="p">(</span><span class="s">&#39;_area&#39;</span><span class="p">,</span><span class="s">&#39;power&#39;</span><span class="p">,</span><span class="s">&#39;angle&#39;</span><span class="p">,</span><span class="s">&#39;weight&#39;</span><span class="p">,</span><span class="s">&#39;residual&#39;</span><span class="p">,</span><span class="s">&#39;smooth&#39;</span><span class="p">,</span><span class="s">&#39;model&#39;</span><span class="p">,</span><span class="s">&#39;mask&#39;</span><span class="p">,</span><span class="s">&#39;noise&#39;</span><span class="p">,</span><span class="s">&#39;label&#39;</span><span class="p">,</span><span class="s">&#39;nhits&#39;</span><span class="p">,</span><span class="s">&#39;covg&#39;</span><span class="p">,</span><span class="s">&#39;std&#39;</span><span class="p">,</span><span class="s">&#39;rms&#39;</span><span class="p">),</span>
        <span class="n">flist</span><span class="o">=</span><span class="s">&#39;find&#39;</span><span class="p">,</span> <span class="n">savedir</span><span class="o">=</span><span class="bp">None</span><span class="p">,</span> <span class="n">clobber</span><span class="o">=</span><span class="bp">True</span><span class="p">,</span> <span class="n">verbose</span><span class="o">=</span><span class="bp">False</span><span class="p">,</span> 
        <span class="o">**</span><span class="n">kwargs</span><span class="p">):</span>
    <span class="sd">&quot;&quot;&quot;</span>
<span class="sd">    Create cutouts from all possible images in the searched directories.</span>
<span class="sd">    &quot;&quot;&quot;</span>

    <span class="k">if</span> <span class="n">flist</span> <span class="o">==</span> <span class="s">&#39;find&#39;</span><span class="p">:</span>
        <span class="c"># Get list</span>
        <span class="n">flist</span> <span class="o">=</span> <span class="n">find_all_images</span><span class="p">(</span><span class="n">xcoord</span><span class="p">,</span> <span class="n">ycoord</span><span class="p">,</span> <span class="n">dirs</span><span class="p">,</span> <span class="n">coordsys</span><span class="o">=</span><span class="n">coordsys</span><span class="p">,</span>
                <span class="n">ignore_imagetypes</span><span class="o">=</span><span class="n">ignore_imagetypes</span><span class="p">,</span> <span class="n">verbose</span><span class="o">=</span><span class="n">verbose</span><span class="p">,</span>
                <span class="n">flatten</span><span class="o">=</span><span class="bp">True</span><span class="p">,</span> <span class="o">**</span><span class="n">kwargs</span><span class="p">)</span>
    <span class="k">elif</span> <span class="nb">type</span><span class="p">(</span><span class="n">flist</span><span class="p">)</span> <span class="ow">not</span> <span class="ow">in</span> <span class="p">(</span><span class="nb">tuple</span><span class="p">,</span><span class="nb">list</span><span class="p">):</span>
        <span class="k">raise</span> <span class="ne">TypeError</span><span class="p">(</span><span class="s">&quot;flist must be a list (or tuple) of filenames&quot;</span><span class="p">)</span>

    <span class="c"># filter out image types I don&#39;t want</span>
    <span class="k">for</span> <span class="n">ign</span> <span class="ow">in</span> <span class="n">ignore_imagetypes</span><span class="p">:</span>
        <span class="n">flist</span> <span class="o">=</span> <span class="n">agpy</span><span class="o">.</span><span class="n">grep</span><span class="o">.</span><span class="n">grepv</span><span class="p">(</span><span class="n">ign</span><span class="p">,</span> <span class="n">flist</span><span class="p">)</span>

    <span class="c"># make all the cutouts</span>
    <span class="n">cutouts</span> <span class="o">=</span> <span class="p">[]</span>
    <span class="k">for</span> <span class="n">fn</span> <span class="ow">in</span> <span class="n">flist</span><span class="p">:</span>
        <span class="k">try</span><span class="p">:</span>
            <span class="n">co</span> <span class="o">=</span> <span class="n">agpy</span><span class="o">.</span><span class="n">cutout</span><span class="o">.</span><span class="n">cutout</span><span class="p">(</span><span class="n">fn</span><span class="p">,</span> <span class="n">xcoord</span><span class="p">,</span> <span class="n">ycoord</span><span class="p">,</span> <span class="n">xwidth</span><span class="p">,</span> <span class="n">ywidth</span><span class="p">,</span> <span class="n">units</span><span class="o">=</span><span class="s">&#39;wcs&#39;</span><span class="p">,</span> <span class="n">coordsys</span><span class="o">=</span><span class="n">coordsys</span><span class="p">,</span> <span class="n">verbose</span><span class="o">=</span><span class="n">verbose</span><span class="p">)</span>
        <span class="k">except</span> <span class="n">agpy</span><span class="o">.</span><span class="n">cutout</span><span class="o">.</span><span class="n">DimensionError</span><span class="p">:</span>
            <span class="n">header</span> <span class="o">=</span> <span class="n">pyfits</span><span class="o">.</span><span class="n">getheader</span><span class="p">(</span><span class="n">fn</span><span class="p">)</span>
            <span class="n">wcs</span> <span class="o">=</span> <span class="n">pywcs</span><span class="o">.</span><span class="n">WCS</span><span class="p">(</span> <span class="n">agpy</span><span class="o">.</span><span class="n">cubes</span><span class="o">.</span><span class="n">flatten_header</span><span class="p">(</span><span class="n">header</span><span class="p">)</span> <span class="p">)</span>
            <span class="n">xc</span><span class="p">,</span><span class="n">yc</span><span class="p">,</span><span class="n">xw</span><span class="p">,</span><span class="n">yw</span> <span class="o">=</span> <span class="n">agpy</span><span class="o">.</span><span class="n">cubes</span><span class="o">.</span><span class="n">aper_world2pix</span><span class="p">((</span><span class="n">xcoord</span><span class="p">,</span><span class="n">ycoord</span><span class="p">,</span><span class="n">xwidth</span><span class="p">,</span><span class="n">ywidth</span><span class="p">),</span><span class="n">wcs</span><span class="p">,</span><span class="n">coordsys</span><span class="o">=</span><span class="n">coordsys</span><span class="p">,</span><span class="n">wunit</span><span class="o">=</span><span class="s">&#39;degree&#39;</span><span class="p">)</span>
            <span class="k">try</span><span class="p">:</span>
                <span class="n">co</span> <span class="o">=</span> <span class="n">agpy</span><span class="o">.</span><span class="n">cubes</span><span class="o">.</span><span class="n">subcube</span><span class="p">(</span> <span class="n">pyfits</span><span class="o">.</span><span class="n">getdata</span><span class="p">(</span><span class="n">fn</span><span class="p">),</span> <span class="n">xcoord</span><span class="p">,</span> <span class="n">xwidth</span><span class="p">,</span> <span class="n">ycoord</span><span class="p">,</span> <span class="n">ywidth</span><span class="p">,</span> <span class="n">header</span><span class="o">=</span><span class="n">header</span><span class="p">,</span> <span class="n">return_HDU</span><span class="o">=</span><span class="bp">True</span><span class="p">,</span> <span class="n">widthunits</span><span class="o">=</span><span class="s">&#39;pixels&#39;</span> <span class="p">)</span>
            <span class="k">except</span> <span class="ne">Exception</span> <span class="k">as</span> <span class="n">ex</span><span class="p">:</span>
                <span class="k">print</span> <span class="s">&quot;</span><span class="si">%s</span><span class="s"> failed: &quot;</span> <span class="o">%</span> <span class="n">fn</span><span class="p">,</span> <span class="n">ex</span>
                <span class="k">continue</span>
        <span class="k">except</span> <span class="ne">Exception</span> <span class="k">as</span> <span class="n">ex</span><span class="p">:</span>
            <span class="k">print</span> <span class="s">&quot;</span><span class="si">%s</span><span class="s"> failed: &quot;</span> <span class="o">%</span> <span class="n">fn</span><span class="p">,</span> <span class="n">ex</span>
            <span class="n">flist</span><span class="o">.</span><span class="n">remove</span><span class="p">(</span><span class="n">fn</span><span class="p">)</span>
            <span class="k">continue</span>
        <span class="n">cutouts</span><span class="o">.</span><span class="n">append</span><span class="p">(</span><span class="n">co</span><span class="p">)</span>
        <span class="k">if</span> <span class="n">savedir</span> <span class="ow">is</span> <span class="ow">not</span> <span class="bp">None</span><span class="p">:</span>
            <span class="k">try</span><span class="p">:</span>
                <span class="n">co</span><span class="o">.</span><span class="n">writeto</span><span class="p">(</span><span class="s">&quot;</span><span class="si">%s</span><span class="s">/</span><span class="si">%s</span><span class="s">&quot;</span> <span class="o">%</span> <span class="p">(</span><span class="n">savedir</span><span class="p">,</span> <span class="n">os</span><span class="o">.</span><span class="n">path</span><span class="o">.</span><span class="n">split</span><span class="p">(</span><span class="n">fn</span><span class="p">)[</span><span class="mi">1</span><span class="p">]</span><span class="o">.</span><span class="n">replace</span><span class="p">(</span><span class="s">&quot;.fits&quot;</span><span class="p">,</span><span class="s">&quot;_cutout.fits&quot;</span><span class="p">)),</span><span class="n">clobber</span><span class="o">=</span><span class="n">clobber</span><span class="p">)</span>
            <span class="k">except</span> <span class="n">pyfits</span><span class="o">.</span><span class="n">VerifyError</span><span class="p">:</span>
                <span class="k">print</span> <span class="s">&quot;Could not verify FITS header for </span><span class="si">%s</span><span class="s">.  Image dimensions were </span><span class="si">%s</span><span class="s">&quot;</span> <span class="o">%</span> <span class="p">(</span><span class="n">fn</span><span class="p">,</span> <span class="n">co</span><span class="o">.</span><span class="n">data</span><span class="o">.</span><span class="n">shape</span><span class="p">)</span>

    <span class="k">return</span> <span class="n">cutouts</span>

<span class="nd">@timer.print_timing</span>
<span class="k">def</span> <span class="nf">find_directories</span><span class="p">(</span><span class="n">rootdir</span><span class="p">,</span> <span class="n">ignoredirs</span><span class="o">=</span><span class="p">(</span><span class="s">&#39;v0.7&#39;</span><span class="p">,</span><span class="s">&#39;powerspectra&#39;</span><span class="p">,</span><span class="s">&#39;AGBT&#39;</span><span class="p">,</span><span class="s">&#39;Frame&#39;</span><span class="p">)):</span>
    <span class="sd">&quot;&quot;&quot;</span>
<span class="sd">    Find directories containing FITS files</span>
<span class="sd">    &quot;&quot;&quot;</span>

    <span class="n">paths</span> <span class="o">=</span> <span class="p">[]</span>
    <span class="k">for</span> <span class="n">root</span><span class="p">,</span><span class="n">dirs</span><span class="p">,</span><span class="n">files</span> <span class="ow">in</span> <span class="n">os</span><span class="o">.</span><span class="n">walk</span><span class="p">(</span><span class="nb">str</span><span class="p">(</span><span class="n">rootdir</span><span class="p">)):</span>
        <span class="k">for</span> <span class="n">igd</span> <span class="ow">in</span> <span class="n">ignoredirs</span><span class="p">:</span>
            <span class="k">if</span> <span class="n">igd</span> <span class="ow">in</span> <span class="n">root</span><span class="p">:</span>
                <span class="k">continue</span>
        <span class="k">if</span> <span class="s">&quot;.fits&quot;</span> <span class="ow">in</span> <span class="p">(</span><span class="nb">str</span><span class="p">(</span><span class="n">os</span><span class="o">.</span><span class="n">path</span><span class="o">.</span><span class="n">splitext</span><span class="p">(</span><span class="n">f</span><span class="p">)[</span><span class="mi">1</span><span class="p">])</span> <span class="k">for</span> <span class="n">f</span> <span class="ow">in</span> <span class="n">files</span><span class="p">):</span> 
            <span class="n">paths</span><span class="o">.</span><span class="n">append</span><span class="p">(</span><span class="n">root</span><span class="p">)</span>

    <span class="k">return</span> <span class="n">paths</span>

<span class="n">default_rootdirs</span> <span class="o">=</span> <span class="p">[</span><span class="s">&#39;/Volumes/disk2/data/&#39;</span><span class="p">,</span><span class="s">&#39;/Volumes/WD_2/HiGal/&#39;</span><span class="p">,</span><span class="s">&#39;/Volumes/disk4/&#39;</span><span class="p">]</span>

<span class="c">#dirs = reduce(lambda a,b: a+b, [find_directories(dr) for dr in default_rootdirs], []) </span>

<span class="n">standard_dirs</span> <span class="o">=</span> <span class="p">[</span>
        <span class="s">&#39;/Volumes/disk2/data/MGPS/&#39;</span><span class="p">,</span>
        <span class="s">&#39;/Volumes/disk2/data/MSX/&#39;</span><span class="p">,</span>
        <span class="s">&#39;/Volumes/disk2/data/WISE/&#39;</span><span class="p">,</span>
        <span class="s">&#39;/Volumes/disk2/data/bally_CO/&#39;</span><span class="p">,</span>
        <span class="s">&#39;/Volumes/disk2/data/bgps/releases/IPAC/&#39;</span><span class="p">,</span>
        <span class="s">&#39;/Volumes/disk2/data/bgps/releases/v2.0/&#39;</span><span class="p">,</span>
        <span class="s">&#39;/Volumes/disk2/data/bgps/releases/v2.0/August2011/&#39;</span><span class="p">,</span>
        <span class="s">&#39;/Volumes/disk2/data/c2d/&#39;</span><span class="p">,</span>
        <span class="s">&#39;/Volumes/disk2/data/cara/csfiles/&#39;</span><span class="p">,</span>
        <span class="s">&#39;/Volumes/disk2/data/cara/glimpsev3/&#39;</span><span class="p">,</span>
        <span class="s">&#39;/Volumes/disk2/data/co/&#39;</span><span class="p">,</span>
        <span class="s">&#39;/Volumes/disk2/data/glimpse/&#39;</span><span class="p">,</span>
        <span class="s">&#39;/Volumes/disk2/data/glimpseii/&#39;</span><span class="p">,</span>
        <span class="s">&#39;/Volumes/disk2/data/grs/&#39;</span><span class="p">,</span>
        <span class="s">&#39;/Volumes/disk2/data/harp/fits/&#39;</span><span class="p">,</span>
        <span class="s">&#39;/Volumes/disk2/data/iras/&#39;</span><span class="p">,</span>
        <span class="s">&#39;/Volumes/disk2/data/magpis/&#39;</span><span class="p">,</span>
        <span class="s">&#39;/Volumes/disk2/data/mips/&#39;</span><span class="p">,</span>
        <span class="s">&#39;/Volumes/disk2/data/mipsgal/&#39;</span><span class="p">,</span>
        <span class="s">&#39;/Volumes/disk2/data/mosaics/&#39;</span><span class="p">,</span>
        <span class="s">&#39;/Volumes/disk2/data/motte/&#39;</span><span class="p">,</span>
        <span class="s">&#39;/Volumes/disk2/data/nvss/&#39;</span><span class="p">,</span>
        <span class="s">&#39;/Volumes/disk2/data/scuba/&#39;</span><span class="p">,</span>
        <span class="s">&#39;/Volumes/disk2/data/sharc/processd/&#39;</span><span class="p">,</span>
        <span class="s">&#39;/Volumes/disk2/data/vgps/&#39;</span><span class="p">,</span>
        <span class="s">&#39;/Volumes/WD_2/HiGal/&#39;</span><span class="p">,</span>
        <span class="s">&#39;/Volumes/disk4/cmz/&#39;</span><span class="p">,</span>
        <span class="s">&#39;/Volumes/disk4/gc/&#39;</span><span class="p">,</span>
        <span class="s">&#39;/Volumes/disk4/higal-gc/&#39;</span><span class="p">,</span>
        <span class="s">&#39;/Volumes/disk4/l44_kirk/&#39;</span><span class="p">,</span>
        <span class="s">&#39;/Volumes/disk4/mosaics/&#39;</span><span class="p">,</span>
        <span class="s">&#39;/Volumes/disk4/nvss/&#39;</span><span class="p">,</span>
        <span class="s">&#39;/Volumes/disk4/orion/&#39;</span><span class="p">,</span>
        <span class="s">&#39;/Volumes/disk4/perseus/&#39;</span><span class="p">,</span>
        <span class="s">&#39;/Volumes/disk4/vlss/&#39;</span><span class="p">,</span>
        <span class="p">]</span>

<span class="n">dirs</span><span class="o">=</span><span class="n">standard_dirs</span>
</pre></div>

          </div>
        </div>
      </div>
        </div>
        <div class="sidebar">
          <h3>Table Of Contents</h3>
          <ul>
<li class="toctree-l1"><a class="reference internal" href="../../agpy.html">Adam Ginsburg&#8217;s Python Code (agpy)</a></li>
<li class="toctree-l1"><a class="reference internal" href="../../image_tools.html">Image Tools</a></li>
<li class="toctree-l1"><a class="reference internal" href="../../fft_tools.html">AG_fft_tools Package</a></li>
<li class="toctree-l1"><a class="reference internal" href="../../plfit.html">plfit Package</a></li>
</ul>

          <h3 style="margin-top: 1.5em;">Search</h3>
          <form class="search" action="../../search.html" method="get">
            <input type="text" name="q" />
            <input type="submit" value="Go" />
            <input type="hidden" name="check_keywords" value="yes" />
            <input type="hidden" name="area" value="default" />
          </form>
          <p class="searchtip" style="font-size: 90%">
            Enter search terms or a module, class or function name.
          </p>
        </div>
        <div class="clearer"></div>
      </div>
    </div>

    <div class="footer">
      &copy; Copyright 2011, Adam Ginsburg.
      Created using <a href="http://sphinx.pocoo.org/">Sphinx</a> 1.2pre.
    <script type="text/javascript">

      var _gaq = _gaq || [];
      _gaq.push(['_setAccount', 'UA-6253248-2']);
      _gaq.push(['_trackPageview']);

      (function() {
        var ga = document.createElement('script'); ga.type = 'text/javascript'; ga.async = true;
        ga.src = ('https:' == document.location.protocol ? 'https://ssl' : 'http://www') + '.google-analytics.com/ga.js';
        var s = document.getElementsByTagName('script')[0]; s.parentNode.insertBefore(ga, s);
      })();

    </script>
        
    </div>
  </body>
</html>